package com.ruoyi.project.business.asynctask.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.business.asynctask.entity.BusinessAsyncTask;
import com.ruoyi.project.business.asynctask.request.ListBusinessAsyncTaskRequest;
import com.ruoyi.project.business.asynctask.request.AddBusinessAsyncTaskRequest;
import com.ruoyi.project.business.asynctask.response.BusinessAsyncTaskResponse;
import com.ruoyi.project.business.asynctask.service.IBusinessAsyncTaskService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.model.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 任务状态Controller
 * 
 * @author ${author}
 * @date 2024-04-11
 */
@RestController
@RequestMapping("/business/asynctask")
public class BusinessAsyncTaskController extends BaseController {
    @Autowired
    private IBusinessAsyncTaskService businessAsyncTaskService;

    /**
     * 查询任务状态列表
     */
    @PreAuthorize("@ss.hasPermi('business:asynctask:list')")
    @GetMapping("/list")
    public TableDataInfo list(ListBusinessAsyncTaskRequest request) {
        startPage();
        Long tenantId = getTenantId();
        List<BusinessAsyncTaskResponse> list = businessAsyncTaskService.selectBusinessAsyncTaskList(request, tenantId);
        return getDataTable(list);
    }

    /**
     * 导出任务状态列表
     */
    @PreAuthorize("@ss.hasPermi('business:asynctask:export')")
    @Log(title = "任务状态", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ListBusinessAsyncTaskRequest request) {
        Long tenantId = getTenantId();
        List<BusinessAsyncTaskResponse> list = businessAsyncTaskService.selectBusinessAsyncTaskList(request, tenantId);
        ExcelUtil<BusinessAsyncTaskResponse> util = new ExcelUtil<>(BusinessAsyncTaskResponse.class);
        return util.exportExcel(list, "asynctask");
    }

    /**
     * 获取任务状态详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:asynctask:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(businessAsyncTaskService.selectBusinessAsyncTaskById(id));
    }

    /**
     * 新增任务状态
     */
    @PreAuthorize("@ss.hasPermi('business:asynctask:add')")
    @Log(title = "任务状态", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AddBusinessAsyncTaskRequest request) {
        Long tenantId = getTenantId();
        Long operatorId = getUserId();
        return toAjax(businessAsyncTaskService.insertBusinessAsyncTask(request, operatorId, tenantId));
    }

    /**
     * 修改任务状态
     */
    @PreAuthorize("@ss.hasPermi('business:asynctask:edit')")
    @Log(title = "任务状态", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BusinessAsyncTask businessAsyncTask) {
        Long tenantId = getTenantId();
        Long operatorId = getUserId();
        return toAjax(businessAsyncTaskService.updateBusinessAsyncTask(businessAsyncTask, operatorId, tenantId));
    }

    /**
     * 删除任务状态
     */
    @PreAuthorize("@ss.hasPermi('business:asynctask:remove')")
    @Log(title = "任务状态", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        Long tenantId = getTenantId();
        Long operatorId = getUserId();
        return toAjax(businessAsyncTaskService.deleteBusinessAsyncTaskByIds(ids, operatorId, tenantId));
    }
}
